package com.company.cloud.web.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.company.cloud.web.service.WebArtService;
import com.company.cloud.web.service.WebIndexService;
import com.company.cloud.web.service.WebPrdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/exhibition")
public class ExhibitionController {

    @Autowired
    private WebIndexService webIndexService;

    @Autowired
    private WebArtService webArtService;

    @Autowired
    private WebPrdService webPrdService;

    /**
     * 会展查询
     */
    @RequestMapping("/expoQuery")
    public String expoQuery(Model model, @RequestParam Map<String, String> params,
                            @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        System.out.println("++++++++++++ ArtistController:list");
        JSONObject data = webArtService.expoQuery(params);
        model.addAttribute("data", data);
        model.addAttribute("params", params);

        return "expo/list";
    }

    /**
     * 会展明细
     */
    @RequestMapping("/expoDetail")
    public String expoDetail(Model model, String expoNo, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        System.out.println("++++++++++++ ArtistController:list");
        JSONObject data = webArtService.expoInfo(expoNo);
        model.addAttribute("data", data);
        return "expo/detail";
    }

    /**
     * 会展公司查询
     */
    @RequestMapping("/expoOrgQuery")
    public String expoOrgQuery(Model model, @RequestParam Map<String, String> params, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        System.out.println("++++++++++++ ArtistController:list");
        JSONObject data = webArtService.expoJoinOrgQuery(params);
        model.addAttribute("data", data);
        model.addAttribute("params", params);
        return "expo/orgList";
    }


    /**
     * 日程
     *
     * @param model
     * @return
     */
    @RequestMapping("/schedule")
    public String schedule(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        model.addAttribute("menu", indexMap.get("menu"));
        model.addAttribute("footer", indexMap.get("footer"));
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/schedule";
    }

    @RequestMapping("/3d")
    public String show3d(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);

        model.addAttribute("i18n", i18n);
        if (i18n.equals("zh-CN")) {
            Map<String, Object> footer = webArtService.staticPageTree("bottom");
            model.addAttribute("footer", footer);
        } else {
            Map<String, Object> footer = webArtService.staticPageTree("bottom-en");
            model.addAttribute("footer", footer);
        }
        model.addAttribute("category", indexMap.get("category"));
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/3d";
    }


    @RequestMapping("/exhibition")
    public String exhibition(Model model, @RequestParam Map<String, String> params,
                             @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {

        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("exCompanyBanner", indexMap.get("exCompanyBanner"));
        params.put("rows", "12");

        JSONObject data = webArtService.organQuery(params);
        model.addAttribute("data", data);
        model.addAttribute("params", params);

        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);

        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);

        model.addAttribute("category", indexMap.get("category"));

        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/exhibition";
    }


    @RequestMapping("/visit")
    public String visit(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        model.addAttribute("menu", indexMap.get("menu"));
        model.addAttribute("footer", indexMap.get("footer"));
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/visit";
    }


    @RequestMapping("/index")
    public String index(Model model,String expoNo, @RequestParam Map<String, String> params, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {

        JSONObject exinfo = webArtService.expoInfo(expoNo);
        model.addAttribute("exinfo", exinfo);

        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        params.put("rows", "500");
        JSONObject data = webArtService.expoJoinOrgQuery(params);
        model.addAttribute("data", data);
        model.addAttribute("params", params);

        params.put("expoNo", expoNo);
        params.put("rows", "500");
        JSONObject list = webArtService.expoJoinOrgQuery(params);
        model.addAttribute("org", list);
        System.out.println(list);
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);

        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        if (i18n.toString().equals("zh-CN")) {

            model.addAttribute("exSchedule", indexMap.get("exSchedule"));
        } else {

            model.addAttribute("exSchedule", indexMap.get("exScheduleen"));
        }

        model.addAttribute("exFile", indexMap.get("exFile"));
        model.addAttribute("category", indexMap.get("category"));
        model.addAttribute("exBanner", indexMap.get("exBanner"));

        model.addAttribute("exMedia", indexMap.get("exMedia"));
        model.addAttribute("exMedia1", indexMap.get("exMedia1"));

        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/index";
    }


    @RequestMapping("/partners")
    public String partners(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        model.addAttribute("menu", indexMap.get("menu"));
        model.addAttribute("footer", indexMap.get("footer"));
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/partners";
    }


    @RequestMapping("/online")
    public String online(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("rows", "100");
        params.put("bizVal1", "1");
        Map<String, Object> expoMap = webArtService.expoQuery(params);
        model.addAttribute("expo", expoMap);
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        model.addAttribute("exOlineBanner", indexMap.get("exOlineBanner"));
        model.addAttribute("exOlineIndex", indexMap.get("exOlineIndex"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);

        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);

        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/online";
    }

    @RequestMapping("/company")
    public String company(Model model, @RequestParam Map<String, String> params, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        JSONObject data = webArtService.organInfo(params.get("companyNo"));
        model.addAttribute("data", data);
        JSONObject list = webArtService.artistList(params);
        model.addAttribute("artist", list);
        JSONObject object = webPrdService.queryPrd(params);
        model.addAttribute("product", object);
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));

        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);

        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);

        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/company";
    }


    @RequestMapping("/exdetail")
    public String exdetail(Model model, String expoNo, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        JSONObject data = webArtService.expoInfo(expoNo);
        model.addAttribute("data", data);
        Map<String, String> params = new HashMap<String, String>();
        params.put("expoNo", expoNo);
        params.put("rows", "500");
        JSONObject list = webArtService.expoJoinOrgQuery(params);
        model.addAttribute("org", list);
        JSONObject product = webArtService.expoWorksQuery(expoNo);
        model.addAttribute("product", product);
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));

        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);

        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);

        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "exhibition/exdetail";
    }


}
